package com.system.demo.utils;

import com.system.demo.entity.excelFile.ApplicationDTO;
import com.system.demo.entity.excelFile.ApplicationDTOForExcel;
import com.system.demo.service.constant.ApplicationStatus;
import com.system.demo.service.constant.CognizanceLevelConstant;
import com.system.demo.service.constant.CognizanceRankConstant;

import static cn.hutool.core.date.DateUtil.formatLocalDateTime;

public class ApplicationDTOMapper {

    public static String mapParticipationMode(Integer mode) {
        switch (mode) {
            case 0: return "线上";
            case 1: return "线下";
            default: return "未知模式";
        }
    }

    public static String mapParticipantType(Integer type) {
        switch (type) {
            case 0: return "个人";
            case 1: return "团队";
            default: return "未知类型";
        }
    }

    public static String mapStatus(Integer status) {
        return ApplicationStatus.getStatusDescription(status);
    }

    public static String mapFinalRankName(Integer finalRankName){
        return CognizanceLevelConstant.getFinalRankNameDescription(finalRankName);
    }

    public static String mapFinalRankLevel(Integer finalRankLevel){
        return CognizanceRankConstant.getFinalRankLevelDescription(finalRankLevel);
    }

    public static ApplicationDTOForExcel mapToExcelDTO(ApplicationDTO dto) {
        ApplicationDTOForExcel excelDto = new ApplicationDTOForExcel();

        excelDto.setParticipationMode(mapParticipationMode(dto.getParticipationMode()));
        excelDto.setParticipantType(mapParticipantType(dto.getParticipantType()));
        excelDto.setStatus(mapStatus(dto.getStatus()));


        // 时间字段的转换
        excelDto.setApplicationCreateTime(formatLocalDateTime(dto.getApplicationCreateTime()));
        excelDto.setFileCreateTime(formatLocalDateTime(dto.getFileCreateTime()));
        excelDto.setCognizanceCreateTime(formatLocalDateTime(dto.getCognizanceCreateTime()));
        // 设置其他属性
        excelDto.setFinalRankLevel(mapFinalRankLevel(dto.getFinalRankLevel()));
        excelDto.setFinalRankName(mapFinalRankName(dto.getFinalRankName()));
        excelDto.setRewardTitle(dto.getRewardTitle());
        excelDto.setFileUrl(dto.getFileUrl());
        excelDto.setTeamRank(dto.getTeamRank());
        excelDto.setTeamMembers(dto.getTeamMembers());
        excelDto.setCompetitionPosition(dto.getCompetitionPosition());
        excelDto.setCompetitionTime(dto.getCompetitionTime());
        excelDto.setCompetitionTutor(dto.getCompetitionTutor());
        excelDto.setCompetitionName(dto.getCompetitionName());
        excelDto.setUid(dto.getUid());
        excelDto.setStudentClass(dto.getStudentClass());
        excelDto.setStudentName(dto.getStudentName());
        excelDto.setId(dto.getId());

        return excelDto;
    }
}